package comframe.jdbc.sql.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

import org.apache.log4j.Logger;

import comframe.jdbc.sql.support.IEx;

public class JdbcProxy implements InvocationHandler{
	private static Logger logger = Logger.getLogger(JdbcProxy.class);
	IEx iex  = null;
	public JdbcProxy(IEx iex) {
		this.iex = iex;
	}
	public Object invoke(Object obj, Method method, Object[] aobj)
			throws Throwable {
		//对象
		Object object = null;
		iex.init();
		try {
			object = method.invoke(iex,aobj);
			//事务提交
			iex.commit();
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage());
			new Exception("sql代理执行失败"+e.getMessage());
		    //回滚
			iex.rollback();
		}finally{
			//关闭连接
			iex.destory();
		}
		
		return object;
	}

}
